package myproject.test;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.log4j.Logger;

public class ReadFileDirectory {
private static final Logger log = Logger.getLogger(ReadFileDirectory.class);
private static final	String  filePath1= "E:\\BaiduNetdiskDownload\\尚硅谷\\";
private static final	String  filePath2= "D:\\BaiduNetdiskDownload\\尚硅谷\\";

	public static void main(String[] args) {
		// TODO Auto-generated method stub
	    List<String> flieList =readDirectory(filePath1);
		List<String> flieList2 =readDirectory(filePath2);
	   
	 	for( String str:flieList){
	 		System.out.println(str);
	 	}
			System.out.println("---------------------------");
	 	for( String str:flieList2){
	 		System.out.println(str);
	 	}
	 	
	 	
	 	Collections.sort(flieList);
	 	Collections.sort(flieList2);
	 	
	 	

	 	try {
			File file = new File(filePath1+"目录清单.txt");//文件路径（路径+文件名）
			if (!file.exists()) {   //文件不存在则创建文件，先创建目录
				File dir = new File(file.getParent());
				dir.mkdirs();
				file.createNewFile();
			}
			FileWriter fileWriter = new FileWriter(file); //文件输出流将数据写入文件
			
			BufferedWriter bw = new BufferedWriter(fileWriter);
					
			System.out.println("flieList.size():"+flieList.size());
			for(int j=0;j<flieList.size();j++) {
				bw.write(flieList.get(j));
				bw.write("\r\n"); 
			}
			bw.write("--------------------------------------------------------"); 
			bw.write("\r\n");
			for(int j=0;j<flieList2.size();j++) {
				bw.write(flieList2.get(j));
				bw.write("\r\n"); 
			}
			bw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//判断是否包含相同目录
	 	flieList.retainAll(flieList2);
        System.out.println("88888888888888888888888888888888888");
        for( String str:flieList){
            System.out.println(str);
        }
		log.info("分类完毕！");
		
	}
	
	

	public static List<String> readDirectory(String path){
		List<String> flieList = new ArrayList<String>();
		File dire=new File(path);
		File[] tempList = dire.listFiles();
		for (int i = 0; i < tempList.length; i++) {
            if (tempList[i].isDirectory()) {
            	flieList.add(tempList[i].getName());
            }
        }
		return flieList;
	}

}
